package main

import (
	"context"
	"errors"
	"fmt"

	"gitee.com/wu-jin-feng/fgin"
	reflectPb "gitee.com/wu-jin-feng/fgin/demos/fconsul_test/server/pb"
)

type DemoServiceServer struct {
	reflectPb.UnimplementedDemoServiceServer
}

func (s *DemoServiceServer) GetScheme(ctx context.Context, req *reflectPb.GetSchemeReq) (*reflectPb.GetSchemeResp, error) {
	if req.Info == nil {
		return nil, errors.New("info 不能为空")
	}
	endData := &reflectPb.GetSchemeResp{
		Data: req.Path + ",gogogo",
		Info: &reflectPb.GetSchemeRespInfo{
			Info: fmt.Sprintf("这是一个info,%s", req.Info.Info),
			Name: fmt.Sprintf("作者是%s", req.Info.Name),
		},
	}
	return endData, nil
}

func main() {
	// fgin.RegisterGrpcServerOptions([]grpc.ServerOption{}, true, true)
	f := fgin.Fgin{}
	s := f.GetGrpcServer("./test.yaml")
	reflectPb.RegisterDemoServiceServer(s, &DemoServiceServer{})
	f.RunGrpc(s)
}
